package megrez.common.spring.data;

import java.io.Serializable;

import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import lombok.ToString;

/**
 * 可编辑视图化实体
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@ToString(callSuper = true)
@MappedSuperclass
public abstract class AbstractEditVO<I extends Serializable, V extends Serializable> extends AbstractBaseVO<I, V> implements Editable {
    private Boolean editable;

    @Override
    public boolean isEditable() {
        return editable == null || Boolean.TRUE.equals(editable);
    }

    @Override
    public boolean isNOtEditable() {
        return Boolean.FALSE.equals(editable);
    }

    @Override
    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    @PrePersist
    @PreUpdate
    public void preAction() {
        if (editable == null) {
            editable = true;
        }
    }

    @Override
    public boolean equals(Object o) {
        return super.equals(o);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    } 

}
